/**
 * Created by Maibenben on 2017/5/10.
 */
$(function () {
    //跳转到本页之后读取cookie中是否有mid和token
    checkCookie();
    var mid = $.cookie("mid");
    var token = $.cookie("token");
    var databack = false;
    //显示数据
    $.get(jianyanURL + location.search + "&mid=" + mid + "&token=" + token, function (res) {
        $("#header>p").text(res.name + "检验报告");
        databack = true;
        $(".load").hide();
        if (res.state == 1) {
            var content = template("repTem", res);
            $(".list").html(content);
            $(".desc").each(function (i, v) {
                var link = v.getAttribute("href");
                link = link + i + "&" + location.search.slice(1);
                v.setAttribute("href", link);
            })
        } else {
            $(".list").html("暂无数据").css({lineHeight: "100px", textAlign: "center", fontSize: "0.8rem"});
        }
    });
    $(".jianyan").click(function () {
        location.reload();
    });
    $(".jiancha").click(function () {
        if (databack) {
            $(this).addClass("active").siblings("p").removeClass("active");
            databack = false;
            $(".list").html("");
            $(".load").show();
            $.get(jianchaURL + location.search + "&mid=" + mid + "&token=" + token, function (res) {
                databack = true;
                $(".load").hide();
                if (res.state == 1) {
                    var checkHtml = template("checkTem", res);
                    $(".list").html(checkHtml);
                } else {
                    creatLayout(res.msg);
                }
                //图片遮罩
                $(".desc").on("click", function () {
                    $("#picMask").attr("src", $(this).attr("data-src")).parents().show();
                });
                $(".closebtn").on("click", function () {
                    $(".piccontainer").hide();
                });
            });
        }
    });
    $(".case").click(function () {
        window.location.href = "case.html" + location.search;
    });
});